package _17_剑指Offer;

import _17_剑指Offer.datastrcute.ListNode;

public class _24_剑指Offer反转链表 {

    // 递归
    public ListNode reverseList(ListNode head) {
        if (head.next == null || head == null) return head;

        ListNode listNode = reverseList(head.next);
        head.next.next = head;
        head.next = null;

        return listNode;
    }

    // 迭代
    public ListNode reverseList1(ListNode head) {

        ListNode prev = null;
        while (head != null) {
            ListNode next = head.next;
            head.next = prev;
            prev = head;
            head = next;
        }
        return prev;
    }

}
